//
//  CookCustomCollectionViewCell.m
//  Delicious2
//
//  Created by dllo on 16/1/7.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "CookCustomCollectionViewCell.h"
#import "NSString+charLine.h"

@implementation CookCustomCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageV = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.labelTitle = [[UILabel alloc] initWithFrame:CGRectZero];
        self.labelTitle.font = [UIFont boldSystemFontOfSize:20];
        
        self.labelSubTitle = [[UILabel alloc] initWithFrame:CGRectZero];
        self.labelSubTitle.font = [UIFont boldSystemFontOfSize:15];
        
     
        [self addSubview:self.imageV];
        [self addSubview:self.labelTitle];
        [self addSubview:self.labelSubTitle];
    }
    return self;
}

- (void)setCookModel:(CookBookModel *)cookModel {
    if (_cookModel != cookModel) {
        _cookModel = cookModel;
    }
    [self.imageV sd_setImageWithURL:[NSURL URLWithString:cookModel.image_url] placeholderImage:[UIImage imageNamed:@"ImagePlace"]];
    
    self.labelTitle.text = [cookModel.title changeLineString];
    self.labelTitle.numberOfLines = [self.labelTitle.text length];
    self.labelTitle.frame = CGRectMake(10, 10, 40, [self.labelTitle.text length] * 14);
    
    //文字竖排
    self.labelSubTitle.text = [cookModel.sub_title changeLineString];
    //自适应高度
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:15]};
    self.labelSubTitle.numberOfLines = 0;
    CGRect rect = [self.labelSubTitle.text boundingRectWithSize:CGSizeMake(WIDTH, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    self.labelSubTitle.frame = CGRectMake(55, 10, 30, rect.size.height);
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super layoutSubviews];
    self.imageV.frame = CGRectMake(90, 0, self.frame.size.width - 100, self.frame.size.height);
//    [self.imageV nightMode];
 
}

@end
